package com.neutech.controller;

import com.mybatisflex.core.paginate.Page;
import com.neutech.vo.ResultJson;
import io.swagger.v3.oas.annotations.Parameters;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import jakarta.annotation.Resource;
import com.neutech.entity.Grade;
import com.neutech.service.GradeService;
import org.springframework.web.bind.annotation.RestController;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import java.util.List;
import java.util.concurrent.TimeUnit;

/**
 * 班级表 控制层。
 *
 * @author Administrator
 * @since 2025-02-08
 */
@RestController
@Tag(name = "班级表接口")
@RequestMapping("/grade")
public class GradeController {

    @Resource
    private GradeService gradeService;

    /**
     * 添加班级表。
     *
     * @param grade 班级表
     * @return {@code true} 添加成功，{@code false} 添加失败
     */
    @PostMapping("add")
    @Operation(summary = "保存班级表", description="保存班级表")
    public ResultJson<Boolean> save(Grade grade) {
        return ResultJson.success(gradeService.save(grade));
    }

    /**
     * 根据主键删除班级表。
     *
     * @param id 主键
     * @return {@code true} 删除成功，{@code false} 删除失败
     */
    @PostMapping("del")
    @Operation(summary = "根据主键班级表", description="根据主键班级表")
    public ResultJson<Boolean> remove(Integer id, Integer active) {
        return ResultJson.success(gradeService.del(id, active));
    }

    /**
     * 根据主键更新班级表。
     *
     * @param grade 班级表
     * @return {@code true} 更新成功，{@code false} 更新失败
     */
    @PostMapping("update")
    @Operation(summary = "根据主键更新班级表", description="根据主键更新班级表")
    ResultJson<Boolean> update(Grade grade) {
        return ResultJson.success(gradeService.updateById(grade));
    }

    /**
     * 查询所有班级表。
     *
     * @return 所有数据
     */
    @GetMapping("list")
    @Operation(summary = "查询所有班级表", description="查询所有班级表")
    @Parameters(value = {
            @Parameter(name = "pageNo", description = "页码"),
            @Parameter(name = "pageSize", description = "每页数量"),
            @Parameter(name = "name", description = "班级名称"),
            @Parameter(name = "active", description = "状态")
    })
    ResultJson<Page<Grade>> list(Integer pageNo, Integer pageSize, String name, Integer active) throws InterruptedException {
        return ResultJson.success(gradeService.list(pageNo, pageSize, name, active));
    }
    /**
     * 根据班级表主键获取详细信息。
     *
     * @param id 班级表主键
     * @return 班级表详情
     */
    @GetMapping("getInfo/{id}")
    @Operation(summary = "根据主键获取班级表", description="根据主键获取班级表")
    ResultJson<Grade> getInfo(@PathVariable("id") Integer id) {
        return ResultJson.success(gradeService.getById(id));
    }


}
